home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 65.zip / BS1 part 65 / Math Visin v2.1 disk 1.adf / Arexx.WB / Animation / MakeAnimation < prev    next >
Text File  |  1992-02-12  |  8KB  |  293 lines

  1. /* MakeAnimation   compress each frame before storing to disk  23-Apr-90 dh 
  2.  
  3.   The program creates animation files directly, by using the program
  4. RecordAnim in the support directory.  Currently, only Delta short compression
  5. is used. 
  6.  
  7.   This program is designed for doing short, generic animations, to be
  8. played with the user's animation player. 
  9.  
  10.   You have the option of varying the coordinates, the parameter 'p', or
  11. both during the animation.
  12.  
  13.   RecordAnim displays an ARexx port named RECORDANIM, and supports the
  14. following commands.
  15.  
  16. OpenAnim Screen Filename
  17.   - opens the file, and allocates buffers
  18.   Screen is exressed in hexadecimal, ie. 27F8C0
  19.   Filename tells what file to create/overwrite
  20. AddFrame
  21.   - adds the contents of the screen to the animation
  22. CloseAnim
  23.   - closes the anim file, deallocates buffers
  24. Quit
  25.   - terminates RecordAnim program, does CloseAnim if necessary
  26.  
  27.  
  28.  
  29.  
  30. ============================================================================ */
  31.  
  32. ADDRESS "MathVision"
  33. OPTIONS RESULTS
  34. OPTIONS FAILAT 20
  35. NUMERIC DIGITS 14
  36. SIGNAL ON ERROR
  37.  
  38. ERR_NO_FILE =  10
  39. ERR_NO_MEMORY = 11
  40.  
  41. Xmin0 = 0; XMax0 = 1
  42. Ymin0 = 0; YMax0 = 1
  43. Xmin1 = 0; XMax1 = 1
  44. Ymin1 = 0; YMax1 = 1
  45.  
  46. VaryCoords = 1
  47. VaryParameter = 0
  48. ParameterStart = 0
  49. ParameterEnd = 1
  50. Frames = 10
  51. FileName = "RAM:Animation"
  52. ClrScr = D2C(12)
  53. StopSign "F"
  54.  
  55.             /* make sure RecordAnim is running */
  56. if (Show("PORTS","RECORDANIM")==0) THEN
  57. DO
  58.   Say "Running RecordAnim"
  59.   ADDRESS COMMAND "Run MathVision:Support/RecordAnim"
  60. END
  61.  
  62. DO WHILE command ~= "X"
  63.   command = MENU()
  64.  
  65.   SELECT
  66.     WHEN command ='V' THEN
  67.       DO 
  68.         VaryCoords = GetBoo("Vary Coordinates", VaryCoords)
  69.         VaryParameter = GetBoo("Vary Parameter", VaryParameter)
  70.       END
  71.     WHEN command ='P' THEN
  72.       DO
  73.         ParameterStart = GetAns("Starting Parameter", ParameterStart )
  74.         ParameterEnd   = GetAns("Ending Parameter", ParameterEnd )
  75.       END
  76.     WHEN command ='C' THEN
  77.       DO 
  78.         if (GetBoo("Change Starting Coordinates", 0)~=0) THEN
  79.           DO
  80.             if (GetBoo("Get Coordinates from MathVision",0)~=0) THEN
  81.               DO
  82.                 Get XMin;  Xmin0 = RESULT
  83.                 Get XMax;  XMax0 = RESULT
  84.                 Get YMin;  Ymin0 = RESULT
  85.                 Get YMax;  YMax0 = RESULT
  86.               END
  87.             ELSE
  88.               DO
  89.                 XMin0 = GetAns("XMin",XMin0)
  90.                 XMax0 = GetAns("XMax",XMax0)
  91.                 YMin0 = GetAns("YMin",YMin0)
  92.                 YMax0 = GetAns("YMax",YMax0)
  93.               END
  94.           END
  95.         if (GetBoo("Change Ending Coordinates", 0)~=0) THEN
  96.           DO
  97.             if (GetBoo("Get Coordinates from MathVision",0)~=0) THEN
  98.               DO
  99.                 Get XMin;  Xmin1 = RESULT
  100.                 Get XMax;  XMax1 = RESULT
  101.                 Get YMin;  Ymin1 = RESULT
  102.                 Get YMax;  YMax1 = RESULT
  103.               END
  104.             ELSE
  105.               DO
  106.                 XMin1 = GetAns("XMin",XMin1)
  107.                 XMax1 = GetAns("XMax",XMax1)
  108.                 YMin1 = GetAns("YMin",YMin1)
  109.                 YMax1 = GetAns("YMax",YMax1)
  110.               END
  111.           END
  112.       END
  113.     WHEN command = 'F' THEN Frames = GetAns("Frames", Frames )
  114.     WHEN command = 'A' THEN CALL Animate
  115.     WHEN command = 'D' THEN Filename = GetAns("Filename", FileName )
  116.     OTHERWISE;
  117.   END /*select*/
  118. END
  119.  
  120. ADDRESS RECORDANIM "Quit"
  121.  
  122. EXIT
  123.  
  124. /*================================== MENU ================================= */
  125.  
  126. MENU:
  127.   SAY ClrScr "---------------- Animate Menu -----------------"
  128.   SAY 
  129.   SAY "V - Vary:  Coordinates=("Boo2Text(VaryCoords)")"
  130.   SAY "           Parameter  =("Boo2Text(VaryParameter)")" 
  131.   if (VaryCoords~=0)
  132.   THEN
  133.     DO
  134.       SAY "C - Coords Start: Xmin " XMin0 " Xmax " XMax0
  135.       SAY "                  Ymin " YMin0 " Ymax " YMax0
  136.       SAY "           End:   Xmin " XMin1 " Xmax " XMax1
  137.       SAY "                  Ymin " YMin1 " Ymax " YMax1
  138.     END
  139.   if (VaryParameter~=0)
  140.   THEN SAY "P - Parameter: ("ParameterStart") to ("ParameterEnd") variable 'p'"
  141.   SAY "F - Frames ("Frames")"
  142.   SAY "D - Filename ("FileName")"
  143.   SAY "A - Animate"
  144.   SAY "X - Exit"
  145.  
  146.   OPTIONS PROMPT "--------------> "
  147.   PULL Command
  148.  
  149.   RETURN command
  150.  
  151. /*================================== ZOOM ================================= */
  152.  
  153. Animate:
  154.  
  155.   Get PlotScreen; Screen = RESULT
  156.   ADDRESS RECORDANIM OpenAnim Screen Filename
  157.   if (rc==ERR_NO_FILE) THEN
  158.   DO
  159.     SayError("Not Enough Memory For Animation")
  160.     return(0)
  161.   END
  162.   if (rc==ERR_NO_FILE) THEN
  163.   DO
  164.     SayError("Could Not Open The File '"filename"'.")
  165.     return(0)
  166.   END
  167.  
  168.   IF (VaryCoords~=0) THEN
  169.   DO
  170.     XCenter0 = (XMin0+XMax0)/2
  171.     YCenter0 = (YMin0+YMax0)/2
  172.     XWidth0 = (XMax0-XMin0)
  173.     YWidth0 = (YMax0-YMin0)
  174.     XCenter1 = (XMin1+XMax1)/2
  175.     YCenter1 = (YMin1+YMax1)/2
  176.     XWidth1 = (XMax1-XMin1)
  177.     YWidth1 = (YMax1-YMin1)
  178.     xfactor = xwidth1/xwidth0
  179.     yfactor = ywidth1/ywidth0
  180.   END
  181.  
  182.   IF (VaryParameter~=0) THEN
  183.   DO
  184.     ParameterWidth = ParameterEnd - ParameterStart
  185.   END
  186.  
  187.  
  188.  PlotScreenToFront
  189.   DO PictureNumber = 0 TO Frames-1     /* for each picture...*/
  190.  
  191.     SAY "Plotting Frame: "PictureNumber
  192.  
  193.     mult = (PictureNumber) / (Frames-1)      /* 0..1 */
  194.  
  195.     IF (VaryParameter~=0) THEN
  196.     DO
  197.       P mult*ParameterWidth+ParameterStart
  198.     END
  199.  
  200.     IF (VaryCoords~=0) THEN
  201.     DO
  202.       if (PictureNumber == 0) THEN  /* avoid ARexx bug with -0 */
  203.       DO 
  204.         XMin Xcenter0-XWidth0/2 
  205.         XMax Xcenter0+XWidth0/2 
  206.         YMin Ycenter0-YWidth0/2 
  207.         YMax Ycenter0+YWidth0/2 
  208.       END
  209.       ELSE
  210.       DO
  211.         xmag = power(xfactor,mult)
  212.         ymag = power(yfactor,mult)
  213.         xwidth = xwidth0*xmag
  214.         ywidth = ywidth0*ymag
  215.         xcenter = xcenter0+((xcenter1-xcenter0)*(xmag-1) / (xfactor-1) )
  216.         ycenter = ycenter0+((ycenter1-ycenter0)*(ymag-1) / (yfactor-1) )
  217.  
  218.         Xmin xcenter-xwidth/2    /* plug in the new values */
  219.         Xmax xcenter+xwidth/2
  220.         Ymin ycenter-ywidth/2
  221.         Ymax ycenter+ywidth/2
  222.       END
  223.     END
  224.  
  225.     Plot          /* do the appropriate plot */
  226.  
  227.     ADDRESS RECORDANIM AddFrame     /* save it in anim file */
  228.  
  229.     Get StopSign
  230.     IF Result = "T" THEN BREAK
  231.   END /* do */
  232.   StopSign "F"
  233.  
  234.   ADDRESS RECORDANIM CloseAnim
  235.   return(0)
  236. RETURN
  237.   
  238. /* --------------------------------- GetAns -------------------------------- */
  239. /* result = GetAns( prompt, default) */
  240. /* prompt for input, displaying default. Accept one item. If only <return> */
  241. /* was pressed, return the default answer */
  242.  
  243. GetAns: PROCEDURE
  244.   parse arg prompter, default
  245.   Options Prompt Prompter "(" Default "): "
  246.   pull response
  247.   if (response = "") THEN response = default;
  248.   return(response)
  249.  
  250. /*------------------------------- GetBoo ----------------------------------- */
  251. /* result = GetBoo( prompt, default) */
  252. /* prompt for boolean input, where 0 means false an <>0 means true */
  253. /* parse the user input appropriately */
  254. GetBoo: PROCEDURE
  255.   parse arg prompter, default
  256.   ans = GetAns( prompter, Boo2Text(default) )
  257.   if (ans==Boo2Text(default))
  258.     THEN return(default);  /* pressed return! */
  259.   ans = left(ans,1,)
  260.   ret = 1
  261.   if(Index("0nN",ans)~=0)
  262.     THEN ret = 0;
  263.   return(ret)
  264.  
  265. /*----------------------------- Boo2Text ----------------------------------- */
  266. /* result = Boo2Text( bnumber ) */
  267. Boo2text:
  268.   parse arg bnumber
  269.   if (bnumber==0)
  270.     THEN return("No")
  271.     ELSE return("Yes")
  272.  
  273. /*------------------------------- SayError --------------------------------- */
  274. /* display error message and wait for action */
  275. SayError: PROCEDURE
  276.   parse arg prompter
  277.   say prompter
  278.   Options Prompt "Press <RETURN> to continue: "
  279.   pull response
  280.   return( 0 )
  281.  
  282. POWER:         /* number to power */
  283.   arg base, pow
  284.   Get Eval base"^"pow   /* kick Mathvision to evaluate this */
  285.   return(result)
  286.  
  287. ERROR:         /* Error Diagnostic for return codes */
  288.   Get Diagnosis RC
  289.   SAY RESULT" on line "SIGL
  290.   DO i = 1 to 5000
  291.   END
  292.   EXIT
  293.